package com.suli.multimedia.controller;

import com.scenic.util.ResponseResult;
import com.suli.multimedia.service.UserService;
import com.suli.multimedia.util.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author admin
 * @version 1.0 <br/>
 * <p style="font-family:SimSun;font-weight:bold">时间:<br/>2022/3/28 22:46</p>
 */

@RestController
@RequestMapping("/oss")
@CrossOrigin("*")
public class OssUploadController {
    @Autowired
    OssUtil ossUtil;  //注入OssUtil
    @Autowired
    UserService userService;
    @PostMapping("/uploadFile")
    public ResponseResult fileUpload(@RequestBody MultipartFile file) {
        try {
            String url = ossUtil.uploadFile(file); //调用OSS工具类
            return ResponseResult.ok().data("imageUrl",url);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error().message("上传失败");
        }
    }
}
